/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;

/**
 *
 * @author Administrator
 */
class Controller {

    Joystick leftJoy = new Joystick(1);
    Joystick rightJoy = new Joystick(2);
    //made new joyostick for the gigawhere
    Joystick gigaware = new Joystick(3);
    boolean neckUp = false;
    boolean Gigaware = true;
   
    public CannonState currentState;
    public disabledState disabled = new disabledState();
    public PressurizingState pressurizing = new PressurizingState();
    public pressurizedState pressurized = new pressurizedState();
    public Filling1State filling1 = new Filling1State();
    public filled1State filled1 = new filled1State();
    public firing1State firing1 = new firing1State();
    public filling2State filling2 = new filling2State();
    public filled2State filled2 = new filled2State();
    public Firing2State firing2 = new Firing2State();
    public safetyState safety = new safetyState();
    public Timer CannonTimer = new Timer();

    private Controller(boolean usingGigaware) {
        Gigaware = usingGigaware;
    }
    private static Controller m_instance;

    public static Controller getInstance() {
        //System.out.println("GetInstance called.");
        if(null == m_instance)
        {
            m_instance = new Controller(true);
            System.out.println("New Controller Allocated");
        }
        else
        {
            System.out.println("Controller is already allocated");
        }
        return m_instance;
    }

    public void update() {
        getJoySwitchButton();
    }

    public double getLeftY() {
        if (Gigaware) {
            return gigaware.getY();
        } else {
            return leftJoy.getY();
        }

    }

    public double getRightY() {
        if (Gigaware) {
            return gigaware.getRawAxis(5); // RawAxis(5) corresponds to the left joystick on the gigaware
        } else {
            return rightJoy.getY();
        }

    }

    //switches between gigaware and joystick drive
    public void getJoySwitchButton() {
        if (!Gigaware) {
            Gigaware = (leftJoy.getRawButton(10));
        }
        if (Gigaware) {
            Gigaware = (!gigaware.getRawButton(10));
        }

    }

    // tells if user wants neck up
    public boolean getExtendNeckButton() {
        return (leftJoy.getRawButton(3) || rightJoy.getRawButton(3) || gigaware.getRawButton(3));
    }

    // tells if user wants neck down
    public boolean getRetractNeckButton() {
        return (leftJoy.getRawButton(2) || rightJoy.getRawButton(2) || gigaware.getRawButton(2));
    }

    public boolean getCompressorOff() {
        return (rightJoy.getRawButton(11) || leftJoy.getRawButton(11));
    }

    public void updateCompressor() {
    }

    public void updateCannonState() {
        if (currentState == null) {
            currentState = disabled;
        }
        if (CannonTimer.get() == 0) {
            CannonTimer.start();
        }

        currentState.UpdateState();

    }

 
    //TODO figure out how to use smart dashboard!!!!

    public void updateCannonSmartDashboard() {
    }
    //TODO

    public boolean pressurizedButton() {
        if (Gigaware) {
            return (gigaware.getRawButton(1));
        }
        return (leftJoy.getRawButton(8) || rightJoy.getRawButton(8));
    }

    public boolean pressurizingButton() {
        if (Gigaware) {
            return(gigaware.getRawButton(9)); 
        }
        return (leftJoy.getRawButton(9) || rightJoy.getRawButton(9));
    }

    public boolean fireButton() {
        if (Gigaware) {
            return (gigaware.getRawButton(6));
        }
        return (leftJoy.getTrigger() || rightJoy.getTrigger());
    }

    public boolean disabledButton() {
        if (Gigaware) {
            return (gigaware.getRawButton(4));
        }
        return (leftJoy.getRawButton(8) || rightJoy.getRawButton(8));
    }

    public boolean safetyButton() {
        if (Gigaware) {
            return (gigaware.getRawButton(2));
        }
        return (leftJoy.getRawButton(11) || rightJoy.getRawButton(11));
    }

    boolean filling1Button() {
        if (Gigaware) {
            return (gigaware.getRawButton(10));
        }

        return (leftJoy.getRawButton(6) || rightJoy.getRawButton(6));
    }

    boolean filling2Button() {
        if (Gigaware) {
            return (gigaware.getRawButton(10));
        }

        return (leftJoy.getRawButton(6) || rightJoy.getRawButton(6));
    }
}
